<?php
$nuevoLink = '';
if(!empty($q)){
        $nuevoLink.="&q=$q";
}
if(!empty($u)){
        $nuevoLink.="&m=$m";
}	
if(!empty($w)){
        $nuevoLink.="&w=$w";
}
if(!empty($i)){
        $nuevoLink.="&i=$i";
}
$paginator->options(array('url'=>array('?'=>'limite='.$limite.''.$nuevoLink)));
?>
<?php echo $javascript->link(array('index_only.js','jquery.adc_report.js'),true);?>
<h2>Listado de Documentos</h2>
<script type="text/javascript">
$(function(){        
    $('.classAnulado').each(function(){
            $(this).css('color','red').find('input:checkbox').remove().end();
            $(this).find('td:first').append('<?php echo $html->image('icons/cancel.png',array('class' =>'loader'));?>');
    });
    $('.classAnuladoItinerante').each(function(){
            $(this).css('color','red');		
    });

    $('.celda tbody tr:not(:last)').each(function(){
            $control = $(this).find('td:nth-child(3)');
            texto = $control.text();
            if(texto==''){
                    $(this).find('td:last').html('')
            }		
    });	
    $('.btnerase, .btnnew').remove();
});
</script>
<?php
function restaFechas($dFecIni, $dFecFin){
    $dFecIni = str_replace("-","",$dFecIni);
    $dFecIni = str_replace("/","",$dFecIni);
    $dFecFin = str_replace("-","",$dFecFin);
    $dFecFin = str_replace("/","",$dFecFin);

    ereg( "([0-9]{1,2})([0-9]{1,2})([0-9]{2,4})", $dFecIni, $aFecIni);
    ereg( "([0-9]{1,2})([0-9]{1,2})([0-9]{2,4})", $dFecFin, $aFecFin);

    $date1 = mktime(0,0,0,$aFecIni[2], $aFecIni[1], $aFecIni[3]);
    $date2 = mktime(0,0,0,$aFecFin[2], $aFecFin[1], $aFecFin[3]);

    return round(($date2 - $date1) / (60 * 60 * 24));
}
function fecha($fecha='', $separador='-', $formatoFecha='d/m/Y'){
        //list($day, $mon, $year) = explode($separador,$fecha);
        list($year, $mon, $day) = explode($separador,$fecha);
	return date($formatoFecha, mktime(0, 0, 0, $mon, $day, $year));
}
function checkRow($obj){			
    $html = $obj['Html'];    
    if($obj['DocumentoVenta']['anulado'] == true){
        $obj['DocumentoVenta']['credito'] = '--';
        return 'classAnulado';
    }
    if($obj['DocumentoVenta']['fecha_emision'] == $obj['DocumentoVenta']['fecha_pago']){
        $obj['DocumentoVenta']['credito'] = '0';
        return $obj['DocumentoVenta']['credito'];
    } else {
        $fecha1= fecha($obj['DocumentoVenta']['fecha_emision']);
        $fecha2= fecha($obj['DocumentoVenta']['fecha_pago']);
        $obj['DocumentoVenta']['credito'] = restaFechas($fecha1,$fecha2);		
        return $obj['DocumentoVenta']['credito'];
    }	
    return false;
}
echo $getList->getFunction('checkRow');
echo $getList->getList(array(
    'Boleta',array(
        'form'=>array('action'=>'process','type'=>'post'),
        'table'=>array('class'=>'celda','border'=>'0'),
        'config'=>array(
            '[DocumentoVenta][id]'=>array('type'=>'hidden','key'=>true ),
            '[id]'=>array('type'=>'checkbox','title'=>''),            
            '[DocumentoVenta][numero_control]'=>array('type'=>'fields','title'=>'# Control'),            
            '[Alumno][codigo]'=>array('title'=>'Codigo','type'=>'fields'),
            '[DocumentoVenta][nombre_cliente]'=>array('type'=>'fields','strong'=>true,'title'=>'Cliente'),            
            '[DocumentoVenta][observaciones]'=>array('type'=>'fields','strong'=>true,'title'=>'Concepto','align'=>'left'),
            '[DocumentoVenta][fecha_emision]'=>array('type'=>'fields','strong'=>true,'title'=>'Fecha','align'=>'left'),
            '[Total]'=>array('type'=>'fields','title'=>'Total',
                        'align'=>'right','fields'=>array(
                            array('[DocumentoVenta][Moneda][simbolo]','[DocumentoVenta][suma_importe_total]'),'%s %s')),
            '[]'=>array('type'=>'button',
                    'href'=>array('action'=>'edit'),'title'=>'E',
                    'class'=>'lnkbutton btnedit','order'=>false)
        ),
        'data'	=>$data,
        'adition'=>array('find'=>true,'paginator'=>true),
        'button'=>array('default'=>true,            
            'Anular'=>array(
                'div' => false,'value'	=>true,
                'name'	=>'cancel','class'	=>'btncancel')            
        )
    )
));
?>